varying vec4 srlPosition;
varying vec4 srlLight;
varying vec4 srlNormal;
varying vec4 srlCamera;
varying vec4 srlSun;

// Tangent space
varying vec3 T;
varying vec3 B;
varying vec3 N;
varying mat3 TBN;

uniform float srlAngle;
uniform vec4 srlSunPos;

uniform vec4 lightPosition;
uniform vec4 Cam;

void main() {

	// Informations
	srlPosition = gl_Vertex;
	srlCamera = normalize(vec4(Cam.x, Cam.y, Cam.z, 1.0));
	srlLight = vec4(lightPosition.x, lightPosition.y, lightPosition.z, 1.0);
	srlNormal = vec4(normalize(gl_Normal), 1.0);
	srlSun = srlSunPos;
	
	// Tangent space
    N = normalize(gl_Normal);
    
    vec3 c1 = cross(gl_Normal, vec3(0.0, 0.0, 1.0)); 
	vec3 c2 = cross(gl_Normal, vec3(0.0, 1.0, 0.0)); 
	if(length(c1)>length(c2))
		T = normalize(c1);
	else
		T = normalize(c2);
	
	B = cross(N, T);
    
    TBN[0] = T;
    TBN[1] = B;
    TBN[2] = N;
       
    // Output        
	gl_FrontColor = gl_Color;
	gl_TexCoord[0] = gl_MultiTexCoord0;
	gl_TexCoord[1] = vec4( TBN * (-srlPosition.xyz) , 1.0);
	gl_Position = ftransform();
}
